package org.xmppbot;

import org.jivesoftware.openfire.PacketRouter;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;

/**
 * Доставляет пакеты соответсвующим ботам
 * @author stas
 *
 */
public class BotPacketRouter implements PacketRouter{

	private IQRouter _iqRouter;
	private MessageRouter _messageRouter;
    /**
     * Routes the given packet based on packet recipient and sender. The
     * router defers actual routing decisions to other classes.
     * <h2>Warning</h2>
     * Be careful to enforce concurrency DbC of concurrent by synchronizing
     * any accesses to class resources.
     *
     * @param packet The packet to route
     */
	@Override
	public void route(Packet packet) {
        if (packet instanceof Message) {
            route((Message)packet);
        }
        else if (packet instanceof Presence) {
            route((Presence)packet);
        }
        else if (packet instanceof IQ) {
            route((IQ)packet);
        }
        else {
            throw new IllegalArgumentException();
        }
	}

	@Override
	public void route(IQ packet) {
		_iqRouter.route(packet);
	}

	@Override
	public void route(Message packet) {
		_messageRouter.route(packet);
	}

	@Override
	public void route(Presence packet) {
//		presenceRouter.route(packet);
	}

}
